package com.ieasy.module.oa.project.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ieasy.basic.dao.IBaseDao;
import com.ieasy.basic.exception.ServiceException;
import com.ieasy.basic.model.DataGrid;
import com.ieasy.basic.model.Msg;
import com.ieasy.basic.model.Pager;
import com.ieasy.basic.model.SystemContext;
import com.ieasy.basic.util.BeanUtils;
import com.ieasy.basic.util.NumberUtil;
import com.ieasy.basic.util.date.DateUtils;
import com.ieasy.basic.util.dbutil.IDBUtilsHelper;
import com.ieasy.module.common.service.BaseService;
import com.ieasy.module.oa.project.entity.ProjectCenter;
import com.ieasy.module.oa.project.entity.ProjectDevWorkTime;
import com.ieasy.module.oa.project.web.form.ProjectCenterForm;
import com.ieasy.module.oa.project.web.form.ProjectDevWorkTimeForm;
import com.ieasy.module.system.entity.PersonEntity;
import com.ieasy.module.system.service.IDeptHistoryService;
import com.ieasy.module.system.service.IPositionHistoryService;
import com.ieasy.module.system.web.form.DeptHistoryForm;
import com.ieasy.module.system.web.form.PositionHistoryForm;

/**
 * 项目开发人员的作业起始时间和加班信息
 * 
 * @author Administrator
 * 
 */
//@Service
//@Transactional
public class ProjectDevWorkTimeService_bak extends BaseService implements IProjectDevWorkTimeService {

	private Log log = LogFactory.getLog(getClass());
	
	//@Inject
	private IDBUtilsHelper dbutil;

	//@Inject
	private IBaseDao<ProjectDevWorkTime> basedaoProjectDevWorkTime;
	
	//@Inject
	private IBaseDao<ProjectCenter> basedaoProject ;
	
	//@Inject
	private IBaseDao<PersonEntity> basedaoPerson ;
	
	//@Inject
	private IPositionHistoryService positionHistoryService ;
	
	//@Inject
	private IDeptHistoryService deptHistoryService ;
	
	//@Autowired
	private IProjectJdlService2 jdlService2 ;
	
	@Override
	public Msg add(ProjectDevWorkTimeForm form) {
		try {
			ProjectDevWorkTime entity = new ProjectDevWorkTime() ;
			BeanUtils.copyNotNullProperties(form, entity) ;
			
			if(form.getProj_id() != null) {
				entity.setProjectCenter(this.basedaoProject.load(ProjectCenter.class, form.getProj_id())) ;
			} else {
				return new Msg(false, "项目的ID不能为空") ;
			}
			
			if(form.getPerson_id() != null) {
				entity.setPerson(this.basedaoPerson.load(PersonEntity.class, form.getPerson_id())) ;
			}
			
			entity.setCreated(new Date()) ;
			entity.setCreateName(getCurrentUser().getEmp_name()) ;
			
			this.basedaoProjectDevWorkTime.add(entity) ;
			
			return new Msg(true, "添加成功");
		} catch (ServiceException e) {
			log.error("添加发生异常", e);
			return new Msg(false, "添加失败");
		}
	}

	@Override
	public Msg delete(ProjectDevWorkTimeForm form) {
		try {
			if(null != form.getIds() && !"".equals(form.getIds())) {
				String[] ids = form.getIds().split(",") ;
				for (String id : ids) {
					this.basedaoProjectDevWorkTime.delete(ProjectDevWorkTime.class, id) ;
				}
			}
			return new Msg(true, "删除成功");
		} catch (ServiceException e) {
			log.error("删除发生异常", e);
			return new Msg(false, "删除失败");
		}
	}
	
	@Override
	public Msg deleteByProjectId(String projectId) {
		try {
			this.basedaoProjectDevWorkTime.executeSQL("delete from ieasy_oa_project_dev_worktime where project_id=?", projectId) ;
			return new Msg(true, "删除成功");
		} catch (ServiceException e) {
			log.error("删除发生异常", e);
			return new Msg(false, "删除失败");
		}
	}

	
	/**
	 * 修改开发人员进入项目的开始和结束日期和加班信息
	 * 客户端传入开发人员进项目的开始和结束日期的数据形式，如下
	 * 作业周期ID，人员ID，人员编号，人员姓名，项目角色，作业开始时间，作业结束时间，平时加班，周末加班，节假日加班，作业状态|作业周期ID，人员ID，人员编号，人员姓名，项目角色，作业开始时间，作业结束时间，平时加班，周末加班，节假日加班，作业状态
	 * @param form
	 * @throws RuntimeException
	 */
	@Override
	public Msg update(ProjectDevWorkTimeForm form) {
		try {
			if(null != form.getId() && !"".equals(form.getId().trim())) {
				String sql = "update ieasy_oa_project_dev_worktime set " +
							 "proj_role=?, work_startDate=?, work_endDate=?, " +
							 "normalHour=?, weekendHour=?, holidaysHour=?, " +
							 "modifyDate=now(), modifyName=?, work_status=? where id=?" ;
				
				this.basedaoProjectDevWorkTime.executeSQL(sql, new Object[]{
						form.getProj_role(), form.getWork_startDate(), form.getWork_endDate(), 
						form.getNormalHour(), form.getWeekendHour(), form.getHolidaysHour(), 
						this.getCurrentUser().getEmp_name(), form.getWork_status(), form.getId()
				}) ;
			}

			return new Msg(true, "修改成功");
		} catch (ServiceException e) {
			log.error("修改发生异常", e);
			return new Msg(false, "修改失败");
		}
	}

	@Override
	public ProjectDevWorkTimeForm getProjectDetail(String id) {

		return null;
	}
	
	/**
	 * 计算人月
	 * 条件：开始日期~结束日期
	 * 每月的工作天数(排除周六日)
	 */
	private void handlerRY(ProjectDevWorkTimeForm pf) {
		Date s_d = pf.getWork_startDate() ;															//开始日期
		Date e_d = pf.getWork_endDate() ;															//结束日期
		
		int startYear = DateUtils.getYear(s_d) ;
		int endYear = DateUtils.getYear(e_d) ;
		int startMonth = DateUtils.getMonth(s_d) ;													//开始的月份
		int endMonth = DateUtils.getMonth(e_d) ;													//结束的月份
		
		float ry = 0f ;																				//人月累计结果
		float ext_ry = 0f ;																			//已消耗的人月
		
		log.debug(pf.getPerson_name());
		for(int i=startYear; i<=endYear; i++) {
			//相同年份
			if(startYear == endYear) {
				log.debug("同年===开始年：" + startYear + "开始月：" + startMonth + "==" + "结束年：" + endYear + "结束月：" + endMonth);
				for(int m=startMonth; m<=endMonth; m++) {
					String forMonth = startYear +"-"+ ((m<10)?"0"+m:m+"") +"-"+ "01" ;	
					Date firstDayMonth = DateUtils.getFirstDayOfMonth(forMonth) ;
					Date lastDayMonth = DateUtils.getLastDayOfMonth(forMonth) ;
					//每月的有效天数（排除周六日）
					//float yxts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
					float yxts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
					
					//开始月和结束月相等（只有一个月）
					if(m==startMonth && m==endMonth) {
						//工作天数（排除周六日）
						//float gzts = ((Integer)DateUtils.getWorkingDay(s_d, e_d)).floatValue() ;
						float gzts = this.jdlService2.getWorkingDayExcludeFirst(s_d, e_d).floatValue() ;
						ry += (gzts/yxts) ;
						
						//计算已消耗人月
						if(DateUtils.compare_date(new Date(), e_d) == 0 || DateUtils.compare_date(new Date(), e_d) == 1) {
							ext_ry = ry ;
						} else {
							//float cur_wd = ((Integer)DateUtils.getWorkingDay(s_d, new Date())).floatValue() ;
							float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(s_d, new Date()).floatValue() ;
							ext_ry += (cur_wd/yxts) ;
						}
						
						log.debug("\t实际日期：" + DateUtils.formatYYYYMMDD(s_d) + "==" + DateUtils.formatYYYYMMDD(e_d) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"===消耗人月："+ext_ry);
					} else {
						//第一个月
						if(m==startMonth) {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(s_d, lastDayMonth)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(s_d, lastDayMonth).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), lastDayMonth) == 0 || DateUtils.compare_date(new Date(), lastDayMonth) == 1) {
								ext_ry = ry ;
							} else {
								float cur_wd = ((Integer)DateUtils.getWorkingDay(s_d, new Date())).floatValue() ;
								ext_ry += (cur_wd/yxts) ;
							}
								
							log.debug("\t[第一个月]实际日期：" + DateUtils.formatYYYYMMDD(s_d) + "==" + DateUtils.formatYYYYMMDD(lastDayMonth) + "==工作天数：" + gzts + "==gzts="+gzts+"+yxts="+yxts+"人月：" + (gzts/yxts) +"===消耗人月："+ext_ry);
						}
						//中间月
						if(m != startMonth && m != endMonth) {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), lastDayMonth) == 0 || DateUtils.compare_date(new Date(), lastDayMonth) == 1) {
								ext_ry = ry ;
							} else {
								Calendar curDate = Calendar.getInstance();
								if(curDate.get(Calendar.YEAR) == i && m == (curDate.get(Calendar.MONTH)+1)) {
									//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
									float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, new Date()).floatValue() ;
									ext_ry += (cur_wd/yxts) ;
								}
							}
							
							
							log.debug("\t[中间月]实际日期：" + DateUtils.formatYYYYMMDD(firstDayMonth) + "==" + DateUtils.formatYYYYMMDD(lastDayMonth) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"===消耗人月："+ext_ry);
						} 
						//最后一个月
						if(m == endMonth && m != startMonth) {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, e_d)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, e_d).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), e_d) == 0 || DateUtils.compare_date(new Date(), e_d) == 1) {
								ext_ry = ry ;
							} else {
								Calendar curDate = Calendar.getInstance();
								if(curDate.get(Calendar.YEAR) == i && m == (curDate.get(Calendar.MONTH)+1)) {
									//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
									float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, new Date()).floatValue() ;
									ext_ry += (cur_wd/yxts) ;
								}
							}
							
							
							log.debug("\t[最后一个月]实际日期：" + DateUtils.formatYYYYMMDD(firstDayMonth) + "==" + DateUtils.formatYYYYMMDD(e_d) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"===消耗人月："+ext_ry);
						}
					}
					
				}
			} else {	//不同年份
				if(i == startYear) {
					log.debug("不同年份#第一年===开始年：" + i + "开始月：" + startMonth + "==" + "结束年：" + endYear + "结束月：" + endMonth);
					for(int m=startMonth; m<=12; m++) {
						String forMonth = startYear +"-"+ ((m<10)?"0"+m:m+"") +"-"+ "01" ;	
						Date firstDayMonth = DateUtils.getFirstDayOfMonth(forMonth) ;
						Date lastDayMonth = DateUtils.getLastDayOfMonth(forMonth) ;
						//每月的有效天数（排除周六日）
						//float yxts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
						float yxts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
						
						//第一年的第一个月
						if(m==startMonth) {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(s_d, lastDayMonth)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(s_d, lastDayMonth).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), lastDayMonth) == 0 || DateUtils.compare_date(new Date(), lastDayMonth) == 1) {
								ext_ry = ry ;
							} else {
								//float cur_wd = ((Integer)DateUtils.getWorkingDay(s_d, new Date())).floatValue() ;
								float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(s_d, new Date()).floatValue() ;
								ext_ry += (cur_wd/yxts) ;
							}
							
							
							log.debug("\t[第一年的第一个月]实际日期：" + DateUtils.formatYYYYMMDD(s_d) + "==" + DateUtils.formatYYYYMMDD(lastDayMonth) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"   以消耗人月：" + ext_ry);
						} else {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), lastDayMonth) == 0 || DateUtils.compare_date(new Date(), lastDayMonth) == 1) {
								ext_ry = ry ;
							} else {
								//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
								Calendar curDate = Calendar.getInstance();
								if(curDate.get(Calendar.YEAR) == i && m == (curDate.get(Calendar.MONTH)+1)) {
									//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
									float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, new Date()).floatValue() ;
									ext_ry += (cur_wd/yxts) ;
								}
							}
							
							log.debug("\t[中间月]实际日期：" + DateUtils.formatYYYYMMDD(firstDayMonth) + "==" + DateUtils.formatYYYYMMDD(lastDayMonth) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"   以消耗人月：" + ext_ry);
						} 
					}
				} else if(i != startYear && i != endYear) {
					log.debug("不同年份#中间年===开始年：" + i + "开始月：" + startMonth + "==" + "结束年：" + endYear + "结束月：" + endMonth);
					for(int m=1; m<=12; m++) {
						String forMonth = i +"-"+ ((m<10)?"0"+m:m+"") +"-"+ "01" ;	
						Date firstDayMonth = DateUtils.getFirstDayOfMonth(forMonth) ;
						Date lastDayMonth = DateUtils.getLastDayOfMonth(forMonth) ;
						//每月的有效天数（排除周六日）
						//float yxts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
						float yxts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
						
						//工作天数（排除周六日）
						//float gzts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
						float gzts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
						ry += (gzts/yxts) ;
						
						//计算已消耗人月
						if(DateUtils.compare_date(new Date(), lastDayMonth) == 0 || DateUtils.compare_date(new Date(), lastDayMonth) == 1) {
							ext_ry = ry ;
						} else {
							//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
							Calendar curDate = Calendar.getInstance();
							if(curDate.get(Calendar.YEAR) == i && m == (curDate.get(Calendar.MONTH)+1)) {
								//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
								float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, new Date()).floatValue() ;
								ext_ry += (cur_wd/yxts) ;
							}
						}
						
						log.debug("\t[中间年-中间月]实际日期：" + DateUtils.formatYYYYMMDD(firstDayMonth) + "==" + DateUtils.formatYYYYMMDD(lastDayMonth) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"   以消耗人月：" + ext_ry);
						
					}
				} else if(i == endYear) {
					log.debug("不同年份#最后年===开始年：" + i + "开始月：" + startMonth + "==" + "结束年：" + endYear + "结束月：" + endMonth);
					for(int m=1; m<=endMonth; m++) {
						String forMonth = i +"-"+ ((m<10)?"0"+m:m+"") +"-"+ "01" ;	
						Date firstDayMonth = DateUtils.getFirstDayOfMonth(forMonth) ;
						Date lastDayMonth = DateUtils.getLastDayOfMonth(forMonth) ;
						//每月的有效天数（排除周六日）
						//float yxts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
						float yxts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
						
						
						//最后一年的中间月
						if(m<endMonth) {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, lastDayMonth)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, lastDayMonth).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), lastDayMonth) == 0 || DateUtils.compare_date(new Date(), lastDayMonth) == 1) {
								ext_ry = ry ;
							} else {
								//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
								Calendar curDate = Calendar.getInstance();
								if(curDate.get(Calendar.YEAR) == i && m == (curDate.get(Calendar.MONTH)+1)) {
									//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
									float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, new Date()).floatValue() ;
									ext_ry += (cur_wd/yxts) ;
								}
							}
							
							log.debug("\t[最后一年的中间月]实际日期：" + DateUtils.formatYYYYMMDD(firstDayMonth) + "==" + DateUtils.formatYYYYMMDD(lastDayMonth) + "==工作天数：" + gzts + "==人月：" + (gzts/yxts) +"   以消耗人月：" + ext_ry);
						} else {
							//工作天数（排除周六日）
							//float gzts = ((Integer)DateUtils.getWorkingDay(firstDayMonth, e_d)).floatValue() ;
							float gzts = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, e_d).floatValue() ;
							ry += (gzts/yxts) ;
							
							//计算已消耗人月
							if(DateUtils.compare_date(new Date(), e_d) == 0 || DateUtils.compare_date(new Date(), e_d) == 1) {
								ext_ry = ry ;
							} else {
								Calendar curDate = Calendar.getInstance();
								if(curDate.get(Calendar.YEAR) == i && m == (curDate.get(Calendar.MONTH)+1)) {
									//float cur_wd = ((Integer)DateUtils.getWorkingDay(firstDayMonth, new Date())).floatValue() ;
									float cur_wd = this.jdlService2.getWorkingDayExcludeFirst(firstDayMonth, new Date()).floatValue() ;
									ext_ry += (cur_wd/yxts) ;
								}
							}
							
							log.debug("\t[最后一年的最后一个月]实际日期：" + DateUtils.formatYYYYMMDD(firstDayMonth) + 
									"==" + DateUtils.formatYYYYMMDD(e_d) + 
									"==工作天数：" + gzts + 
									"==人月：" + (gzts/yxts) +
									"==以消耗人月：" + ext_ry);
						} 
					}
				}
				
			}
		}
		
		pf.setRy(NumberUtil.formatNum(ry)) ;
		pf.setExt_ry(NumberUtil.formatNum(ext_ry)) ;
	}
	
	@Override
	public DataGrid datagrid(ProjectDevWorkTimeForm form) {
		Map<String, Object> map = new HashMap<String, Object>() ;
		if(null == form.getSort()) {
			SystemContext.setSort("d.created") ;
		} else {
			SystemContext.setSort("d."+form.getSort()) ; SystemContext.setOrder(form.getOrder()) ;
		}
		try {
			List<ProjectDevWorkTimeForm> forms = new ArrayList<ProjectDevWorkTimeForm>() ;
			Pager<ProjectDevWorkTimeForm> pager = this.find(form) ;
			//根据工作状态
			Collections.sort(pager.getDataRows(), new Comparator<ProjectDevWorkTimeForm>() {  
	            public int compare(ProjectDevWorkTimeForm arg0, ProjectDevWorkTimeForm arg1) {  
	                int a1 = arg0.getWork_status();  
	                int a2 = arg1.getWork_status();  
	                if (a1 < a2) {  
	                    return 1;  
	                } else {  
	                    return -1;  
	                }  
	            }  
	        });
				
			int cycTotal = 0 ;								//开发周期
			int ext_cycTotal = 0 ;							//开发周期
			float total_ry = 0f ;							//统计人月
			float total_extRy = 0f ;						//统计已消耗人月
			float n = 0f ;									//平时加班
			float w = 0f ;									//周六日加班
			float h = 0f ;									//节假日加班
			float totalHour = 0f ;							//累计加班小时
			
			if (null != pager && !pager.getDataRows().isEmpty()) {
				for(ProjectDevWorkTimeForm pf : pager.getDataRows()) {
					//取得人员岗位变更历史
					PositionHistoryForm phf = new PositionHistoryForm() ;
					phf.setPersonId(pf.getPerson_id());
					List<PositionHistoryForm> list = this.positionHistoryService.list(phf) ;
					pf.setPersonPositionHistory(list);
					
					//取得人员岗位变更历史
					DeptHistoryForm dhf = new DeptHistoryForm() ;
					dhf.setPersonId(pf.getPerson_id());
					List<DeptHistoryForm> dlist = this.deptHistoryService.list(dhf) ;
					pf.setDeptHistory(dlist);
					
					if(null != pf.getWork_startDate() && null != pf.getWork_endDate()) {
						//工作天数（排除周六日）
						//int workingDay = DateUtils.getWorkingDay(pf.getWork_startDate(), pf.getWork_endDate()) ;
						int workingDay = this.jdlService2.getWorkingDayExcludeFirst(pf.getWork_startDate(), pf.getWork_endDate()) ;
						
						n += pf.getNormalHour() ;
						w += pf.getWeekendHour() ;
						h += pf.getHolidaysHour() ;
						
						//已消耗的天数
						int ext_devCyc = 0 ;
						if(DateUtils.compare_date(new Date(), pf.getWork_endDate()) == 0 || 1 == DateUtils.compare_date(new Date(), pf.getWork_endDate())) {
							//ext_devCyc = DateUtils.getWorkingDay(pf.getWork_startDate(), pf.getWork_endDate()) ;
							ext_devCyc = this.jdlService2.getWorkingDayExcludeFirst(pf.getWork_startDate(), pf.getWork_endDate()) ;
						} else {
							//ext_devCyc = DateUtils.getWorkingDay(pf.getWork_startDate(), new Date()) ;
							ext_devCyc = this.jdlService2.getWorkingDayExcludeFirst(pf.getWork_startDate(), new Date()) ;
						}
						
						//开发周期
						pf.setDevCyc(workingDay) ;
						//已消耗天数（消耗的开发周期）
						pf.setExt_devCyc(ext_devCyc) ;
						pf.setTotalHour(NumberUtil.formatNum(pf.getNormalHour() + pf.getWeekendHour() + pf.getHolidaysHour())) ;
						
						cycTotal += pf.getDevCyc() ;
						totalHour += pf.getTotalHour() ;
						ext_cycTotal += ext_devCyc ;
						
						//加班率
						pf.setJbl(NumberUtil.percent((pf.getNormalHour()+pf.getWeekendHour()+pf.getHolidaysHour())/(workingDay*8), 1));
						
						//处理人月
						this.handlerRY(pf) ;
						
						total_ry += pf.getRy() ;
						total_extRy += pf.getExt_ry() ;
					}
					forms.add(pf) ;
				}
			}
			
			//页脚
			map.put("devCyc", cycTotal) ;
			map.put("ext_devCyc", ext_cycTotal) ;
			map.put("normalHour", NumberUtil.formatNum(n)) ;
			map.put("weekendHour", NumberUtil.formatNum(w)) ;
			map.put("holidaysHour", NumberUtil.formatNum(h)) ;
			map.put("totalHour", NumberUtil.formatNum(totalHour)) ;
			/*总加班小时/(总工作天数*8)*/
			map.put("jbl", NumberUtil.percent(totalHour/(cycTotal*8), 1)) ;
			map.put("ry", NumberUtil.formatNum(total_ry)) ;
			map.put("ext_ry", NumberUtil.formatNum(total_extRy)) ;
			
			List<Map<String, Object>> footerList = new ArrayList<Map<String, Object>>() ;
			footerList.add(map) ;
			
			DataGrid dg = new DataGrid() ;
			dg.setTotal(pager.getTotal());
			dg.setRows(forms);
			dg.setFooter(footerList) ;
			
			return dg;
		} catch (Exception e) {
			log.error("查询项目开发人员起止日期信息失", e) ;
			throw new ServiceException("查询项目开发人员起止日期信息失", e) ;
		}
	}
	
	@Override
	public DataGrid datagridRy(ProjectDevWorkTimeForm form) {
		int year = form.getYear() ;
		
		List<Map<String, Object>> footerList = new ArrayList<Map<String, Object>>() ;
		Map<String, Object> map = new HashMap<String, Object>() ;
		map.put("month1", 0);
		map.put("month2", 0);
		map.put("month3", 0);
		map.put("month4", 0);
		map.put("month5", 0);
		map.put("month6", 0);
		map.put("month7", 0);
		map.put("month8", 0);
		map.put("month9", 0);
		map.put("month10", 0);
		map.put("month11", 0);
		map.put("month12", 0);
		
		ProjectCenterForm project = findProject(form.getProj_id()) ;
		log.debug("项目：" + project.getProj_name() + "\t 查询年份：" + year);
		
		List<ProjectDevWorkTimeForm> forms = new ArrayList<ProjectDevWorkTimeForm>() ;
		Pager<ProjectDevWorkTimeForm> pager = findDevListByRy(form) ;
		
		for (ProjectDevWorkTimeForm pd : pager.getDataRows()) {
			log.debug(pd.getPerson_name() + 
					"\t" + pd.getWork_startDate() + 
					"==" + pd.getWork_endDate() +
					"\t" + DateUtils.getYear(pd.getWork_startDate()) + "===" + DateUtils.getYear(pd.getWork_endDate())) ;
		}
		
		log.debug("----------------------忧伤的分割线----------------------");
		
		
		for (ProjectDevWorkTimeForm pd : pager.getDataRows()) {
			
			if(DateUtils.getYear(pd.getWork_startDate()) <= year && DateUtils.getYear(pd.getWork_endDate()) >= year) {
				/*System.out.print(pd.getPerson_name() + 
						"\t" + pd.getWork_startDate() + 
						"==" + pd.getWork_endDate() +
						"\t" + DateUtils.getYear(pd.getWork_startDate()) + "===" + DateUtils.getYear(pd.getWork_endDate())) ;*/
				
				//个人工作的开始和结束年份
				int startYear = DateUtils.getYear(pd.getWork_startDate()) ;
				int endYear = DateUtils.getYear(pd.getWork_endDate()) ;
				
				//个人工作的开始和结束月份
				int startMonth = DateUtils.getMonth(pd.getWork_startDate()) ;
				int endMonth = DateUtils.getMonth(pd.getWork_endDate()) ;
				
				//开始月
				Integer sm = DateUtils.getMonth(pd.getWork_startDate()) ;
				//结束月
				Integer em = DateUtils.getMonth(pd.getWork_endDate()) ;
				
				/*************************开始年&&结束年都==指定查询年*************************/
				if(startYear == year && endYear == year) {
					//System.out.print("\t开始年&&结束年都==指定查询年\r");
					
					for(int i=startMonth; i<=endMonth; i++) {
						String forMonth = year+"-"+ ((i<10)?"0"+i:i+"") +"-"+ "01" ;
						if(sm == em) {
							int workingDay = DateUtils.getWorkingDay(pd.getWork_startDate(), pd.getWork_endDate()) ;
							log.debug("\t"+i+"月"+
									"\t"+pd.getWork_startDate()+"=="+
									DateUtils.formatYYYYMMDD(pd.getWork_endDate())+
									"\t工作天数："+workingDay);
							
							//设置开发人员的人日明细
							setDevPersonRenRi(pd, i, workingDay) ;
						} else {
							//第一个月
							if(i==startMonth) {
								//工作天数
								int workingDay = DateUtils.getWorkingDay(pd.getWork_startDate(), DateUtils.getLastDayOfMonth(forMonth)) ;
								log.debug("\t"+i+"月"+
										"\t"+pd.getWork_startDate()+"=="+
										DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
										"\t工作天数："+workingDay);
								
								//设置开发人员的人日明细
								setDevPersonRenRi(pd, i, workingDay) ;
							}
							
							//中间月份
							if(i!=startMonth&&i!=endMonth) {
								//工作天数
								int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), DateUtils.getLastDayOfMonth(forMonth)) ;
								log.debug("\t"+i+"月"+
										"\t"+forMonth+"=="+
										DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
										"\t工作天数："+workingDay);
								
								//设置开发人员的人日明细
								setDevPersonRenRi(pd, i, workingDay) ;
							}
							
							
							//最后一个月，并且结束的月份不等于指定月份
							if(i==endMonth) {
								//工作天数
								int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), pd.getWork_endDate()) ;
								log.debug("\t"+i+"月"+
										"\t"+forMonth+"=="+
										pd.getWork_endDate()+
										"\t工作天数："+workingDay);
								
								//设置开发人员的人日明细
								setDevPersonRenRi(pd, i, workingDay) ;
							}
						}
					}
					
				}
				
				/*************************开始年==指定查询年&&结束年!=指定查询年*************************/
				if (startYear == year && endYear != year) {
					//System.out.print("\t开始年==指定查询年&&结束年!=指定查询年\r");
					
					for(int i=startMonth; i<=12; i++) {
						String forMonth = year+"-"+ ((i<10)?"0"+i:i+"") +"-"+ "01" ;
						
						//第一个月
						if(i==startMonth) {
							//工作天数
							int workingDay = DateUtils.getWorkingDay(pd.getWork_startDate(), DateUtils.getLastDayOfMonth(forMonth)) ;
							log.debug("\t"+i+"月"+
									"\t"+pd.getWork_startDate()+"=="+
									DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
									"\t工作天数："+workingDay);
							
							//设置开发人员的人日明细
							setDevPersonRenRi(pd, i, workingDay) ;
						}
						
						//中间月份
						if(i!=startMonth&&i!=12) {
							//工作天数
							int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), DateUtils.getLastDayOfMonth(forMonth)) ;
							log.debug("\t"+i+"月"+
									"\t"+forMonth+"=="+
									DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
									"\t工作天数："+workingDay);
							
							//设置开发人员的人日明细
							setDevPersonRenRi(pd, i, workingDay) ;
						}
						
						//最后一个月
						if(i==12 && i != startMonth) {
							//工作天数
							int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), DateUtils.getLastDayOfMonth(forMonth)) ;
							log.debug("\t"+i+"月"+
									"\t"+forMonth+"=****="+
									DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
									"\t工作天数："+workingDay);
							
							//设置开发人员的人日明细
							setDevPersonRenRi(pd, i, workingDay) ;
						}
					}
					
				}
				
				/*************************开始年!=指定查询年&&结束年==指定查询年*************************/
				if (startYear != year && endYear == year) {
					//System.out.print("\t开始年!=指定查询年&&结束年==指定查询年\r");
					
					for(int i=1; i<=endMonth; i++) {
						String forMonth = year+"-"+ ((i<10)?"0"+i:i+"") +"-"+ "01" ;
						
						//开始和中间月份
						if(i!=endMonth) {
							//工作天数
							int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), DateUtils.getLastDayOfMonth(forMonth)) ;
							log.debug("\t"+i+"月"+
									"\t"+forMonth+"=="+
									DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
									"\t工作天数："+workingDay);
							
							//设置开发人员的人日明细
							setDevPersonRenRi(pd, i, workingDay) ;
						}
						
						
						//最后一个月
						if(i==endMonth) {
							//工作天数
							int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), pd.getWork_endDate()) ;
							log.debug("\t"+i+"月"+
									"\t"+forMonth+"=="+
									pd.getWork_endDate()+
									"\t工作天数："+workingDay);
							
							//设置开发人员的人日明细
							setDevPersonRenRi(pd, i, workingDay) ;
						}
					}
				}
				
				/*************************开始年!=指定查询年&&结束年!=指定查询年*************************/
				if(startYear != year && endYear != year) {
					System.out.print("\t开始年!=指定查询年&&结束年!=指定查询年\r");
					
					for(int i=1; i<=12; i++) {
						String forMonth = year+"-"+ ((i<10)?"0"+i:i+"") +"-"+ "01" ;
						
						//工作天数
						int workingDay = DateUtils.getWorkingDay(DateUtils.getFirstDayOfMonth(forMonth), DateUtils.getLastDayOfMonth(forMonth)) ;
						log.debug("\t"+i+"月"+
								"\t"+forMonth+"=="+
								DateUtils.formatYYYYMMDD(DateUtils.getLastDayOfMonth(forMonth))+
								"\t工作天数："+workingDay);
						
						//设置开发人员的人日明细
						setDevPersonRenRi(pd, i, workingDay) ;
					}
					
				}
				
				forms.add(pd) ;
			}
			
			
		}
		for(ProjectDevWorkTimeForm pd : forms) {
			map.put("month1", (null!= map.get("month1")? Integer.parseInt(map.get("month1").toString()) + pd.getMonth1() : pd.getMonth1())) ;
			map.put("month2", (null!= map.get("month2")? Integer.parseInt(map.get("month2").toString()) + pd.getMonth2() : pd.getMonth2())) ;
			map.put("month3", (null!= map.get("month3")? Integer.parseInt(map.get("month3").toString()) + pd.getMonth3() : pd.getMonth3())) ;
			map.put("month4", (null!= map.get("month4")? Integer.parseInt(map.get("month4").toString()) + pd.getMonth4() : pd.getMonth4())) ;
			map.put("month5", (null!= map.get("month5")? Integer.parseInt(map.get("month5").toString()) + pd.getMonth5() : pd.getMonth5())) ;
			map.put("month6", (null!= map.get("month6")? Integer.parseInt(map.get("month6").toString()) + pd.getMonth6() : pd.getMonth6())) ;
			map.put("month7", (null!= map.get("month7")? Integer.parseInt(map.get("month7").toString()) + pd.getMonth7() : pd.getMonth7())) ;
			map.put("month8", (null!= map.get("month8")? Integer.parseInt(map.get("month8").toString()) + pd.getMonth8() : pd.getMonth8())) ;
			map.put("month9", (null!= map.get("month9")? Integer.parseInt(map.get("month9").toString()) + pd.getMonth9() : pd.getMonth9())) ;
			map.put("month10", (null!= map.get("month10")? Integer.parseInt(map.get("month10").toString()) + pd.getMonth10() : pd.getMonth10())) ;
			map.put("month11", (null!= map.get("month11")? Integer.parseInt(map.get("month11").toString()) + pd.getMonth11() : pd.getMonth11())) ;
			map.put("month12", (null!= map.get("month12")? Integer.parseInt(map.get("month12").toString()) + pd.getMonth12() : pd.getMonth12())) ;
			//log.debug(pd.getMonth1()+pd.getMonth2()+pd.getMonth3()+pd.getMonth4()+pd.getMonth5()+pd.getMonth6()+pd.getMonth7()+pd.getMonth8()+pd.getMonth9()+pd.getMonth10()+pd.getMonth11()+pd.getMonth12());
		}
		
		
		footerList.add(map) ;
		
		DataGrid dg = new DataGrid() ;
		dg.setTotal(pager.getTotal());
		dg.setRows(forms);
		dg.setFooter(footerList) ;
		
		return dg;
	}
	
	private void setDevPersonRenRi(ProjectDevWorkTimeForm pd, int i, int workingDay) {
		
		switch (i) {
		case 1:
			pd.setMonth1(workingDay);
			break;
		case 2:
			pd.setMonth2(workingDay);
			break;
		case 3:
			pd.setMonth3(workingDay);
			break;
		case 4:
			pd.setMonth4(workingDay);
			break;
		case 5:
			pd.setMonth5(workingDay);
			break;
		case 6:
			pd.setMonth6(workingDay);
			break;
		case 7:
			pd.setMonth7(workingDay);
			break;
		case 8:
			pd.setMonth8(workingDay);
			break;
		case 9:
			pd.setMonth9(workingDay);
			break;
		case 10:
			pd.setMonth10(workingDay);
			break;
		case 11:
			pd.setMonth11(workingDay);
			break;
		case 12:
			pd.setMonth12(workingDay);
			break;
		default:
			break;
		}
		
	}

	private ProjectCenterForm findProject(String projectId) {
		String sql = "" +
				"SELECT "+
				"	p.proj_name, "+
				"	p.proj_start_time, "+
				"	p.proj_end_time "+
				"FROM "+
				"	ieasy_oa_project_center p "+
				"WHERE "+
				"	p.id=?" ;
		return (ProjectCenterForm) this.basedaoProject.queryObjectSQL(sql, new Object[]{projectId}, ProjectCenterForm.class, false) ;
	}
	
	private Pager<ProjectDevWorkTimeForm> findDevListByRy(ProjectDevWorkTimeForm form) {
		Map<String, Object> alias = new HashMap<String, Object>();
		String sql = "" +
				"SELECT " +
				"	d.proj_name, " +
				"	d.person_num, " +
				"	d.person_name, " +
				"	d.work_startDate, " +
				"	d.work_endDate, " +
				"	d.positionId, " +
				"	d.positionName, " +
				"	d.deptId, " +
				"	d.deptName " +
				//"	position.id as positionId, " +
				//"	position.name as positionName, " +
				//"	dept.id dept_id, " +
				//"	dept.name dept_name " +
				"FROM " +
				"	ieasy_oa_project_dev_worktime d " +
				"left join ieasy_sys_person p ON(p.id=d.person_id) " +
				//"left join ieasy_sys_org dept ON(dept.id=p.org_id) " +
			 	//"left join ieasy_sys_position position ON(position.id=p.position_id) " +
				"WHERE " +
				"	1=1 " ;
		sql = addWhere(sql, form, alias) ;
		return this.basedaoProjectDevWorkTime.findSQL(sql, alias, ProjectDevWorkTimeForm.class, false) ;
	
	}
	
	
	
	@Override
	public List<ProjectDevWorkTimeForm> listDev(ProjectDevWorkTimeForm form) {
		Map<String, Object> alias = new HashMap<String, Object>();
		String sql = "select " +
					 "d.id, d.person_id, d.person_num, d.person_name, d.project_id as proj_id, d.proj_num, " +
					 "d.proj_name, d.proj_role, d.work_startDate, d.work_endDate, d.work_status, " +
					 "d.normalHour, d.weekendHour, d.holidaysHour, d.createName, d.created, d.modifyName, d.modifyDate, " +
					 "p.dbmType, p.dbmDate, p.lbmType, p.lbmDate, p.positionRecord, p.empState empStatus, " +
					 "pc.proj_quot, " +
					 "dept.name dept_name, " +
					 "pos.name positionName  " +
				 	 "from ieasy_oa_project_dev_worktime d " +
				 	 "left join ieasy_oa_project_center pc ON(pc.id=d.project_id) " +
				 	 "left join ieasy_sys_person p ON(p.id=d.person_id) " +
				 	 "left join ieasy_sys_org dept ON(dept.id=p.org_id) " +
				 	 "left join ieasy_sys_position pos ON(pos.id=p.position_id) " +
				 	 "where 1=1 ";
		sql = addWhere(sql, form, alias) ;
		return this.basedaoProjectDevWorkTime.listSQL(sql, alias, ProjectDevWorkTimeForm.class, false) ;
	}
	
	private Pager<ProjectDevWorkTimeForm> find(ProjectDevWorkTimeForm form) {
		Map<String, Object> alias = new HashMap<String, Object>();
		String sql = "select " +
					 "d.id, d.person_id, d.person_num, d.person_name, d.project_id as proj_id, d.proj_num, " +
					 "d.proj_name, d.proj_role, d.work_startDate, d.work_endDate, d.work_status, " +
					 "d.normalHour, d.weekendHour, d.holidaysHour, d.createName, d.created, d.modifyName, d.modifyDate, " +
					 "p.dbmType, p.dbmDate, p.lbmType, p.lbmDate, p.positionRecord, p.empState empStatus, " +
					 "pc.proj_quot, pc.proj_owner_dept_name proj_dept, " +
					 //"dept.name dept_name, " +
					 "d.positionId,  " +
					 "d.positionName,  " +
					 "d.deptId,  " +
					 "d.deptName  " +
					 //"pos.id positionId,  " +
					 //"pos.name positionName  " +
				 	 "from ieasy_oa_project_dev_worktime d " +
				 	 "left join ieasy_oa_project_center pc ON(pc.id=d.project_id) " +
				 	 "left join ieasy_sys_person p ON(p.id=d.person_id) " +
				 	 //"left join ieasy_sys_org dept ON(dept.id=p.org_id) " +
				 	 //"left join ieasy_sys_position pos ON(pos.id=p.position_id) " +
				 	 "where 1=1 ";
		sql = addWhere(sql, form, alias) ;
		return this.basedaoProjectDevWorkTime.findSQL(sql, alias, ProjectDevWorkTimeForm.class, false) ;
	}
	
	private String addWhere(String sql, ProjectDevWorkTimeForm form, Map<String, Object> params) {
		if (null != form) {
			if (form.getId() != null && !"".equals(form.getId().trim())) {
				sql += " and d.id=:id";
				params.put("id", form.getId());
			}
			if (form.getProj_id() != null && !"".equals(form.getProj_id().trim())) {
				sql += " and d.project_id=:project_id";
				params.put("project_id", form.getProj_id());
			}
			if (form.getPerson_id() != null && !"".equals(form.getPerson_id().trim())) {
				sql += " and d.person_id=:person_id";
				params.put("person_id", form.getPerson_id());
			}
			if (form.getWork_status() != null) {
				sql += " and d.work_status=:work_status";
				params.put("work_status", form.getWork_status());
			}
			//按开始日期进行范围查询
			if (form.getWork_begin_startDate() != null) {
				sql += " and date_format(d.work_startDate,'%Y-%m-%d')>= date_format(:work_begin_startDate,'%Y-%m-%d') ";
				params.put("work_start_time", form.getWork_begin_startDate());
			}
			if (form.getWork_begin_endDate() != null && !"".equals(form.getWork_begin_endDate())) {
				sql += " and date_format(d.work_startDate,'%Y-%m-%d')<= date_format(:work_start_time,'%Y-%m-%d') ";
				params.put("work_start_time", form.getWork_begin_endDate());
			}
			//按结束日期进行范围查询
			if (form.getWork_finish_startDate() != null) {
				sql += " and date_format(d.work_endDate,'%Y-%m-%d')>= date_format(:work_finish_startDate,'%Y-%m-%d') ";
				params.put("work_finish_startDate", form.getWork_finish_startDate());
			}
			if (form.getWork_finish_endDate() != null && !"".equals(form.getWork_finish_endDate())) {
				sql += " and date_format(d.work_endDate,'%Y-%m-%d')<= date_format(:work_finish_endDate,'%Y-%m-%d') ";
				params.put("work_finish_endDate", form.getWork_finish_endDate());
			}
		}
		return sql;
	}
	
	@Override
	public Msg exitProjectBatch(ProjectDevWorkTimeForm form) {
		try {
			if(null != form.getIds() && !"".equals(form.getIds())) {
				String[] ids = form.getIds().split(",") ;
				String[] nums = form.getPerson_nums().split(",") ;
				for(int i=0;i<ids.length;i++) {
					
					//修改开发人员的工作状态为退出项目，如果开发人员的结束时间大于今天，则将结束日期修改为今天的日期
					this.dbutil.getQr().update("update ieasy_oa_project_dev_worktime t set " +
							"t.work_status=0, " +
							"t.work_endDate=CASE WHEN date_format(t.work_endDate,'%Y-%m-%d')>date_format(NOW(),'%Y-%m-%d') THEN date_format(NOW(),'%Y-%m-%d') ELSE t.work_endDate END " +
							"where t.id=? and t.project_id=?", new Object[]{ids[i], form.getProj_id()}) ;
					
					//修改人员的状态为待机状态
					this.dbutil.getQr().update("update ieasy_sys_person set byProjectWorkStatus=1 where id=?", new Object[]{
							nums[i]
					});
				}
			}
			return new Msg(true, "修改成功！") ;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new Msg(false, "修改失败！") ;
	}

	@Override
	public Msg exitProject(ProjectDevWorkTimeForm form) {
		try {
			//修改开发人员的工作状态为退出项目，如果开发人员的结束时间大于今天，则将结束日期修改为今天的日期
			this.dbutil.getQr().update("update ieasy_oa_project_dev_worktime t set " +
					"t.work_status=0, " +
					"t.work_endDate=CASE WHEN date_format(t.work_endDate,'%Y-%m-%d')>date_format(NOW(),'%Y-%m-%d') THEN date_format(NOW(),'%Y-%m-%d') ELSE t.work_endDate END " +
					"where t.id=? and t.project_id=?", new Object[]{form.getId(), form.getProj_id()}) ;
			
			//修改人员的状态为待机状态
			this.dbutil.getQr().update("update ieasy_sys_person set byProjectWorkStatus=1 where id=?", new Object[]{
					form.getPerson_num()
			});
			return new Msg(true, "修改成功！") ;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new Msg(false, "修改失败！") ;
	}

	@Override
	public Msg modifySEDate(ProjectDevWorkTimeForm form) {
		try {
			//修改已退出人员的开始和结束时间
			this.dbutil.getQr().update("update ieasy_oa_project_dev_worktime set work_startDate=?, work_endDate=? where id=?", new Object[]{
					form.getWork_startDate(), form.getWork_endDate(), form.getId()
			}) ;
			return new Msg(true, "修改成功！") ;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new Msg(false, "修改失败！") ;
	}
	
	@Override
	public Msg deleteDevPerson(ProjectDevWorkTimeForm form) {
		try {
			//删除开发人员的数据
			this.dbutil.getQr().update("delete from ieasy_oa_project_dev_worktime where id=?", new Object[]{
					form.getId()
			}) ;
			//修改人员的状态为待机状态
			this.dbutil.getQr().update("update ieasy_sys_person set byProjectWorkStatus=1 where id=?", new Object[]{
					form.getPerson_id()
			});
			
			return new Msg(true, "删除成功！") ;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return new Msg(false, "删除失败！") ;
	}

	//http://localhost:8080/ieasy/admin/oa/project/open_project_UI.do?projectId=4028824e574fb7e70157a88a74d60135&status=2
	@SuppressWarnings("unchecked")
	@Override
	public DataGrid by_project_dev_position_datagrid(ProjectDevWorkTimeForm form) {
		SystemContext.setPage(1);
		SystemContext.setRows(10000);
		Map<String, ProjectDevWorkTimeForm> map = new HashMap<String, ProjectDevWorkTimeForm>() ;
		
		DataGrid datagridRy = datagridRy(form);
		List<ProjectDevWorkTimeForm> rows = (List<ProjectDevWorkTimeForm>) datagridRy.getRows() ;
		
		for (ProjectDevWorkTimeForm p : rows) {
			ProjectDevWorkTimeForm mapProject = map.get(p.getPositionId()) ;
			if(null != mapProject) {
				//天数
				p.setMonth1(p.getMonth1() + mapProject.getMonth1());
				p.setMonth2(p.getMonth2() + mapProject.getMonth2());
				p.setMonth3(p.getMonth3() + mapProject.getMonth3());
				p.setMonth4(p.getMonth4() + mapProject.getMonth4());
				p.setMonth5(p.getMonth5() + mapProject.getMonth5());
				p.setMonth6(p.getMonth6() + mapProject.getMonth6());
				p.setMonth7(p.getMonth7() + mapProject.getMonth7());
				p.setMonth8(p.getMonth8() + mapProject.getMonth8());
				p.setMonth9(p.getMonth9() + mapProject.getMonth9());
				p.setMonth10(p.getMonth10() + mapProject.getMonth10());
				p.setMonth11(p.getMonth11() + mapProject.getMonth11());
				p.setMonth12(p.getMonth12() + mapProject.getMonth12());
			}
			map.put(p.getPositionId(), p) ;
		}
		
		//清空Rows数据
		datagridRy.getRows().removeAll(datagridRy.getRows());
		
		//新的Rows数据
		List<ProjectDevWorkTimeForm> newRows = (List<ProjectDevWorkTimeForm>) datagridRy.getRows() ;
		for (String key : map.keySet()) {
			ProjectDevWorkTimeForm pf = map.get(key);
			//人月
			pf.setM1(NumberUtil.formatNum(Float.valueOf(pf.getMonth1()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+1+"-"+1)))); 
			pf.setM2(NumberUtil.formatNum(Float.valueOf(pf.getMonth2()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+2+"-"+1)))); 
			pf.setM3(NumberUtil.formatNum(Float.valueOf(pf.getMonth3()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+3+"-"+1)))); 
			pf.setM4(NumberUtil.formatNum(Float.valueOf(pf.getMonth4()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+4+"-"+1)))); 
			pf.setM5(NumberUtil.formatNum(Float.valueOf(pf.getMonth5()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+5+"-"+1)))); 
			pf.setM6(NumberUtil.formatNum(Float.valueOf(pf.getMonth6()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+6+"-"+1)))); 
			pf.setM7(NumberUtil.formatNum(Float.valueOf(pf.getMonth7()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+7+"-"+1)))); 
			pf.setM8(NumberUtil.formatNum(Float.valueOf(pf.getMonth8()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+8+"-"+1)))); 
			pf.setM9(NumberUtil.formatNum(Float.valueOf(pf.getMonth9()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+9+"-"+1)))); 
			pf.setM10(NumberUtil.formatNum(Float.valueOf(pf.getMonth10()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+10+"-"+1)))); 
			pf.setM11(NumberUtil.formatNum(Float.valueOf(pf.getMonth11()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+11+"-"+1)))); 
			pf.setM12(NumberUtil.formatNum(Float.valueOf(pf.getMonth12()) / Float.valueOf(DateUtils.getMonthWorkDay(form.getYear()+"-"+12+"-"+1)))); 
			
			newRows.add(pf);
		}
		
		//获取页脚
		List<Map<String, Object>> footer = (List<Map<String, Object>>) datagridRy.getFooter();
		Map<String, Object> mapFooter = footer.get(0) ;
		mapFooter.put("m1", 0);
		mapFooter.put("m2", 0);
		mapFooter.put("m3", 0);
		mapFooter.put("m4", 0);
		mapFooter.put("m5", 0);
		mapFooter.put("m6", 0);
		mapFooter.put("m7", 0);
		mapFooter.put("m8", 0);
		mapFooter.put("m9", 0);
		mapFooter.put("m10", 0);
		mapFooter.put("m11", 0);
		mapFooter.put("m12", 0);
		
		for (ProjectDevWorkTimeForm pf : newRows) {
			//追加人月合计到页脚
			mapFooter.put("m1", (null!= mapFooter.get("m1")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m1").toString()) + pf.getM1()) : pf.getM1())) ;
			mapFooter.put("m2", (null!= mapFooter.get("m2")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m2").toString()) + pf.getM2()) : pf.getM2())) ;
			mapFooter.put("m3", (null!= mapFooter.get("m3")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m3").toString()) + pf.getM3()) : pf.getM3())) ;
			mapFooter.put("m4", (null!= mapFooter.get("m4")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m4").toString()) + pf.getM4()) : pf.getM4())) ;
			mapFooter.put("m5", (null!= mapFooter.get("m5")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m5").toString()) + pf.getM5()) : pf.getM5())) ;
			mapFooter.put("m6", (null!= mapFooter.get("m6")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m6").toString()) + pf.getM6()) : pf.getM6())) ;
			mapFooter.put("m7", (null!= mapFooter.get("m7")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m7").toString()) + pf.getM7()) : pf.getM7())) ;
			mapFooter.put("m8", (null!= mapFooter.get("m8")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m8").toString()) + pf.getM8()) : pf.getM8())) ;
			mapFooter.put("m9", (null!= mapFooter.get("m9")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m9").toString()) + pf.getM9()) : pf.getM9())) ;
			mapFooter.put("m10", (null!= mapFooter.get("m10")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m10").toString()) + pf.getM10()) : pf.getM10())) ;
			mapFooter.put("m11", (null!= mapFooter.get("m11")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m11").toString()) + pf.getM11()) : pf.getM11())) ;
			mapFooter.put("m12", (null!= mapFooter.get("m12")? NumberUtil.formatNum(Float.parseFloat(mapFooter.get("m12").toString()) + pf.getM12()) : pf.getM12())) ;
			
		}
		SystemContext.removeAll();
		return datagridRy;
	}
	
}
